package com.wr.hangzhounewlight.service.frontend;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wr.hangzhounewlight.mapper.ChangeLogMapper;
import com.wr.hangzhounewlight.obj.database.ChangeLogEntity;
import com.wr.hangzhounewlight.obj.dto.frontend.ChangeLogDTO;
import com.wr.hangzhounewlight.obj.dto.frontend.R;
import com.wr.hangzhounewlight.obj.vo.frontend.ChangeLogVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yuanzhizhuo
 * createDate 2025/11/14
 */
@Service
public class ChangeLogService {

    private final ChangeLogMapper changeLogMapper;

    public ChangeLogService(ChangeLogMapper changeLogMapper) {
        this.changeLogMapper = changeLogMapper;
    }

    public R queryChangeLog(ChangeLogDTO dto) {
        LambdaQueryWrapper<ChangeLogEntity> queryWrapper = new LambdaQueryWrapper<ChangeLogEntity>()
                .select(
                        ChangeLogEntity::getOrderNo, ChangeLogEntity::getCheckMessage,
                        ChangeLogEntity::getLog, ChangeLogEntity::getInsertTime
                )
                .eq(ChangeLogEntity::getOrderNo, dto.getOrderNo())
                .eq(ChangeLogEntity::getCheckMessage, dto.getCheckMessage())
                .between(ChangeLogEntity::getInsertTime, dto.getStartDateTime(), dto.getEndDateTime())
                .orderByDesc(ChangeLogEntity::getInsertTime);
        List<ChangeLogVO> voList = changeLogMapper.selectList(queryWrapper).stream().map(ChangeLogVO::new).toList();
        return new R(200, "success", voList);
    }

}
